**************************************************************
** title:	Elderly and COVID-19							**
** journal: PloS One										**
** author:	Jean-François Daoust							**
** date:	June 2020										**
**************************************************************

**************************************************************
** 				Merging + preparing datasets				**
**************************************************************

*First, you need to download to dataset on LIC-YouGov iithub website or on my Harvard dataverse. 
*Then, we run lines 17-235 to create the dataset in which we will conduct the analyses

*Set wd
cd "/Users/jfd/Desktop/June_11_covid-19-tracker-master/data"

*Load to canada dataset
use australia.dta, clear
*Append the other datasets (needs to be in .dta -- see the 'preparation' if needed
append using brazil canada china denmark finland france germany hong_kong india indonesia italy japan malaysia mexico ///
		netherlands norway philippines saudi_arabia singapore south_korea spain sweden taiwan thailand uae uk usa vietnam, force

*Drop China and Indonesia  because of their non-representative sample (see the Data section of the text for details). Skip the line if you want to include them
drop if china==1 | india==1

*Label
label define COUTRYNAMES 1 "Australia" 2 "Brazil" 3 "Canada" 5 "Denmark" 6 "Finland" 7 "France" 8 "Germany" 9 "Hong Kong"  11 "Indonesia" 12 "Italy" ///
		13 "Japan" 14 "Malaysia" 15 "Mexico" 16 "Netherlands" 17 "Norway" 18 "Philippines" 19 "Saudi Arabia" 20 "Singapore" 21 "South Korea" 22 "Spain" 23 "Sweden" 24 "Taiwan" ///
		25 "Thailand" 26 "UAE" 27 "United Kingdom" 28 "United States" 29 "Vietnam", replace
label value  countryid COUTRYNAMES

***********
** DVs   **
***********

*Atittude 1
*Isolation prospective
*Thinking about the next 7 days... would you isolate yourself after feeling unwell or having any of the following new symptoms: a dry cough, fever, loss of sense of smell, loss of sense of taste, shortness of breath or difficulty breathing?
gen isolate_prospective=0 if i9_health=="No"
replace isolate_prospective=0 if i9_health=="Not sure"
replace isolate_prospective=1 if i9_health=="Yes"

*Atittude 2
*Willingness to isolate
gen isolation_willingness=0 if i11_health=="Very unwilling"
replace isolation_willingness=0.25 if i11_health=="Somewhat unwilling"
replace isolation_willingness=0.5 if i11_health=="Not sure" | i11_health=="Neither willing nor unwilling"
replace isolation_willingness=0.75 if i11_health=="Somewhat willing"
replace isolation_willingness=1 if i11_health=="Very willing"


*Behaviour multi-item
forval i = 1/20 {
	gen behaviour`i' =0 if i12_health_`i'=="Not at all"
	replace behaviour`i' =0.25 if i12_health_`i'=="Rarely"
	replace behaviour`i' =0.5 if i12_health_`i'=="Sometimes"
	replace behaviour`i' =0.75 if i12_health_`i'=="Frequently"
	replace behaviour`i' =1 if i12_health_`i'=="Always"
 }

*Drop the follwing 4 items: go to hospital/healthcare (7), work outside (9), children go to school (10), sleep separately (17) -- See footnote 4 and the robustness checks section of the text  for details
drop behaviour7 behaviour9 behaviour10 behaviour17 

*Total
egen index = rowtotal(behaviour*) 
 
***************
**Covariates***
***************

*Wave.- the meaning varies by country (see lines 120-2)
tab qweek, generate(wave)
 
*Sex
gen woman=0
replace woman=1 if gender=="Female"

*Region
encode region, gen(region_fe)

*Employment status
replace employment_status="" if employment_status==" "
tab employment_status, gen(status)

gen work_fulltime=0
replace work_fulltime=1 if employment_status=="Full time employment"
gen work_parttime=0
replace work_parttime=1 if employment_status=="Part time employment"
gen student=0
replace student=1 if employment_status=="Full time student" // student means full time student
gen other=0
replace other=1 if employment_status=="Other"
gen retired=0
replace retired=1 if employment_status=="Retired"
gen unemployed=0
replace unemployed=1 if employment_status=="Unemployed"

*Children (not asked in Indonesia, Philippines and Taiwan)
gen children=0 if household_children=="0"
replace children=1 if household_children=="1" | household_children=="2" | household_children=="3" | ///
		household_children=="4" | household_children=="5 or more" | household_children=="6" | household_children=="7" | household_children=="8" | household_children=="9" 

*Living alone
gen alone=0
replace alone=1 if household_size=="1"
replace alone=. if household_size=="Don't know" | household_size=="Prefer not to say" | household_size==" " | household_size==""

*Time the variable qweek identifies the wave for each country, but regardless of other countries. 
*For example, qweek=2 is Australia is 07/04-09/04 while it is much later in Canada (30/04-01/05). We need to manually generate a time-consistent variable.
*We use 15 days intervals where the end of the field must fit within the timeline. See Table SM.1 for the starrt/end of the fields

*Fiedl within April 1st and 15th
gen april1_15=0
replace april1_15=1 if australia==1 & qweek=="week 1" | australia==1 & qweek=="week 2" 
replace april1_15=1 if brazil==1 & qweek=="week 1" 
replace april1_15=1 if canada==1 & qweek=="week 1" 
replace april1_15=1 if denmark==1 & qweek=="week 1" 
replace april1_15=1 if finland==1 & qweek=="week 1" 
replace april1_15=1 if france==1 & qweek=="week 1" | france==1 & qweek=="week 2" 
replace april1_15=1 if germany==1 & qweek=="week 1" | germany==1 & qweek=="week 2" 
replace april1_15=1 if indonesia==1 & qweek=="week 1" 
replace april1_15=1 if italy==1 & qweek=="week 1" | italy==1 & qweek=="week 2" 
replace april1_15=1 if japan==1 & qweek=="week 1" 
replace april1_15=1 if malaysia==1 & qweek=="week 1" 
replace april1_15=1 if mexico==1 & qweek=="week 1" 
replace april1_15=1 if netherlands==1 & qweek=="week 1" 
replace april1_15=1 if norway==1 & qweek=="week 1" 
replace april1_15=1 if philippines==1 & qweek=="week 1" 
replace april1_15=1 if singapore==1 & qweek=="week 1" | singapore==1 & qweek=="week 2" 
replace april1_15=1 if south_korea==1 & qweek=="week 1" 
replace april1_15=1 if spain==1 & qweek=="week 1" | spain==1 & qweek=="week 2" 
replace april1_15=1 if sweden==1 & qweek=="week 1" | sweden==1 & qweek=="week 2" 
replace april1_15=1 if taiwan==1 & qweek=="week 1" 
replace april1_15=1 if thailand==1 & qweek=="week 1" 
replace april1_15=1 if uae==1 & qweek=="week 1" 
replace april1_15=1 if uk==1 & qweek=="week 1" | uk==1 & qweek=="week 2" 
replace april1_15=1 if usa==1 & qweek=="week 1" | usa==1 & qweek=="week 2" 
replace april1_15=1 if vietnam==1 & qweek=="week 1" 

*Field within April 16th and 30th
gen april16_30=0
replace april16_30=1 if australia==1 & qweek=="week 3" | australia==1 & qweek=="week 4" 
replace april16_30=1 if denmark==1 & qweek=="week 2" 
replace april16_30=1 if finland==1 & qweek=="week 2" 
replace april16_30=1 if france==1 & qweek=="week 3" | france==1 & qweek=="week 4" 
replace april16_30=1 if germany==1 & qweek=="week 3" | germany==1 & qweek=="week 4" 
replace april16_30=1 if hong_kong==1 & qweek=="week 1" 
replace april16_30=1 if italy==1 & qweek=="week 3" | italy==1 & qweek=="week 4" 
replace april16_30=1 if mexico==1 & qweek=="week 2" 
replace april16_30=1 if saudi_arabia==1 & qweek=="week 1" 
replace april16_30=1 if spain==1 & qweek=="week 3" | spain==1 & qweek=="week 4" 
replace april16_30=1 if sweden==1 & qweek=="week 3" | sweden==1 & qweek=="week 4" 
replace april16_30=1 if taiwan==1 & qweek=="week 2" 
replace april16_30=1 if thailand==1 & qweek=="week 2" 
replace april16_30=1 if uk==1 & qweek=="week 3" | uk==1 & qweek=="week 4" 
replace april16_30=1 if usa==1 & qweek=="week 3" | usa==1 & qweek=="week 4" 

*Field include May
gen may1_15=0
replace may1_15=1 if australia==1 & qweek=="week 5" 
replace may1_15=1 if canada==1 & qweek=="week 2" 
replace may1_15=1 if france==1 & qweek=="week 5" 
replace may1_15=1 if germany==1 & qweek=="week 5" 
replace may1_15=1 if italy==1 & qweek=="week 5" 
replace may1_15=1 if indonesia==1 & qweek=="week 2" 
replace may1_15=1 if malaysia==1 & qweek=="week 2" 
replace may1_15=1 if netherlands==1 & qweek=="week 2" 
replace may1_15=1 if norway==1 & qweek=="week 2" 
replace may1_15=1 if philippines==1 & qweek=="week 2" 
replace may1_15=1 if spain==1 & qweek=="week 5" 
replace may1_15=1 if sweden==1 & qweek=="week 5" 
replace may1_15=1 if uk==1 & qweek=="week 5" 
replace may1_15=1 if vietnam==1 & qweek=="week 2" 

*One single variable for time
gen time1_time2_time3=1 if april1_15==1
replace time1_time2_time3=2 if april16_30==1
replace time1_time2_time3=3 if may1_15==1

*Age groups for Table SM.3
gen age18_29=0
replace age18_29=1 if age <30
gen age30_39=0
replace age30_39=1 if age >29 & age <40
gen age40_49=0
replace age40_49=1 if age >39 & age <50
gen age50_59=0
replace age50_59=1 if age >49 & age <60
gen age60_69=0
replace age60_69=1 if age >59 & age <70
gen age70_79=0
replace age70_79=1 if age >69 & age <80
gen age80_89=0
replace age80_89=1 if age >79 

gen age_group=1 if age18_29==1
replace age_group=2 if age30_39==1
replace age_group=3 if age40_49==1
replace age_group=4 if age50_59==1
replace age_group=5 if age60_69==1
replace age_group=6 if age70_79==1
replace age_group=7 if age80_89==1

**************************************************************
** 							Labels							**
**************************************************************

 label variable isolate_prospective "Isolation prospective"
 label variable isolation_willingness "Isolation willingness"
 label variable woman "Sex (Woman=1)"
 label variable qweek "Wave"
 label variable status1 "Full time employment"
 label variable status2 "Full time student"
 label variable status3 "Not working"
 label variable status4 "Other"
 label variable status5 "Part time employment"
 label variable status6 "Retired"
 label variable status7 "Unemployed"
 
**************************************************************
** 						Cleaning							**
**************************************************************

*Drop if the data were not included in the intitial submission (for an updated version of the analyses that integrated the weeks after wave 5 just skip the next line)
 drop if time1_time2_time3==. & china !=1 & india !=1
 
*Drop age when values has <10 observations 
drop if age >89

**************************************************************
** 				Descriptives of DVs and IV					**
**************************************************************
*Age - Figure 1
hist age,  xlabel(20(5)90) xtitle("Age (18 to 89 years old)") frequency  discrete

*Figure SM1
hist isolate_prospective,  xtitle("")  title("Prospective isolation") xlabel(-0.5 " " 0 "No/not sure" 1 "Yes" 1.5 " ") freq ylabel(, format(%5.0f) ang(h))
graph save sm1_1.gph, replace
hist isolation_willingness,    xlabel(0 `" "Very"  "unwilling" "' 0.25 `" "Somewhat"  "unwilling" "' 0.5 `" "Neither willing nor"  "unwilling/Not sure" "' 0.75 `" "Somewhat"  "willing" "' 1 `" "Very"  "willing" "') ///
				ylabel(, format(%5.0f) ang(h)) title("Willingness to isolate") xtitle("") freq  	
graph save sm1_2.gph, replace
hist index,  xtitle("") xlabel(0(2)16) title("Index of compliance" "with preventive measures") freq ylabel(, format(%5.0f) ang(h)) discrete
graph save sm1_3.gph, replace

graph combine sm1_1.gph sm1_2.gph sm1_3.gph, col(1) xsize(12) ysize(15) 

*Table SM.2
eststo clear
eststo: quietly estpost sum age woman children alone  status* april1_15 april16_30 may1_15 
esttab using "tables_m2.rtf", cells("min mean(fmt(3)) sd(fmt(3)) max count")  label  mlabels(,titles) replace
	 
**************************************************************
** 						ATTITUDES 							**
**************************************************************

**********
**Prospective isolation
**********
twoway lpolyci isolate_prospective age, level(84) legend(off) saving(isolate_prospective_pooled.gph, replace)  ///
		 ylabel(.6(.1)1) title("panel a")   xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save fig2_1.gph, replace
			 
**********
**Isolation willingness
**********
twoway lpolyci isolation_willingness age, level(84) legend(off) saving(isolation_willingness_pooled.gph, replace)  ///
		 ylabel(.6(.1)1)  title("panel b")  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Willingness to isolate")  
graph save fig2_2.gph, replace

		
*Combine both attitudes	(pooled)
graph combine fig2_1.gph  fig2_2.gph , col(1) ysize(18) xsize(12)


**************************************************************
** 						COMPLIANCE 							**
**************************************************************

**********
**Index***
**********

****Indexpooled	 
twoway lpolyci index age, level(84) legend(off)   ///
		 ylabel(6(2)16)  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Compliance with preventive measures") 
graph save fig3.gph, replace	  

********************************
**Figure 4 - Particular items***
********************************
	  
twoway lpolyci behaviour1 age, level(84)  legend(off)  title("panel a") ///
		 ylabel(0(.1)1)  xlabel(20(10)90) legend(off) xtitle("") ytitle("Worn a mask")  
graph save fig4_1.gph, replace		  
		 
twoway lpolyci behaviour8 age, level(84)  legend(off)  title("panel b") ///
		 ylabel(0(.1)1)  xlabel(20(10)90) legend(off) xtitle("") ytitle("Avoided public transport")  
graph save fig4_2.gph, replace		  
		
twoway lpolyci behaviour12 age, level(84)  legend(off)  title("panel c")  ///
		 ylabel(0(.1)1)  xlabel(20(10)90) legend(off) xtitle("Age") ytitle("Avoided small gatherings")  
graph save fig4_3.gph, replace		  
	
twoway lpolyci behaviour11 age, level(84)  legend(off)  title("panel d") ///
		 ylabel(0(.1)1)  xlabel(20(10)90) legend(off) xtitle("Age") ytitle("Avoided having guests over")  
graph save fig4_4.gph, replace		  
	
		
graph combine fig4_1.gph  fig4_2.gph fig4_3.gph  fig4_4.gph , col(2) ysize(14) xsize(12)
	
	
**************************************************************
** 					Robustness checks 						**
**************************************************************

**Figure SM.2

*Mask Wear
twoway lpolyci behaviour1 age, level(84)  legend(off) saving(figsm2_1.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall) )  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Worn a mask", size(vsmall))  

*Wash hand
twoway lpolyci behaviour2 age, level(84)  legend(off) saving(figsm2_2.gph, replace)  ///
			 ylabel(0(.2)1, labsize(vsmall)) xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick) legend(off) xtitle("") title("Wash hands", size(vsmall))  

*Use hand sanitizer
twoway lpolyci behaviour3 age, level(84)  legend(off) saving(figsm2_3.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Use hand sanitizer", size(vsmall)) 

*Sneeze or cough safely
twoway lpolyci behaviour4 age, level(84)  legend(off) saving(figsm2_4.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Sneeze or cough safely", size(vsmall)) 

*Avoid people with symptoms or exposed to covid
twoway lpolyci behaviour5 age, level(84)  legend(off) saving(figsm2_5.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoid people with symptoms/exposed", size(vsmall))
	 
*Avoid going out in general
twoway lpolyci behaviour6 age, level(84)  legend(off) saving(figsm2_6.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoid going out in general", size(vsmall))  

*Avoid public transport
twoway lpolyci behaviour8 age, level(84)  legend(off) saving(figsm2_7.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoid public transport", size(vsmall))  
		 
*Avoid having guest over
twoway lpolyci behaviour11 age, level(84)  legend(off) saving(figsm2_8.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoid having guests over", size(vsmall)) 

*Avoid small gatherings
twoway lpolyci behaviour12 age, level(84)  legend(off) saving(figsm2_9.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall)) xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick) legend(off) xtitle("") title("Avoid small gatherings", size(vsmall)) 

*Avoir medium-sized gatherings
twoway lpolyci behaviour13 age, level(84)  legend(off) saving(figsm2_10.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall)) xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoir medium-sized gatherings", size(vsmall)) 
	 
*Avoid large-sized gatherings
twoway lpolyci behaviour14 age, level(84)  legend(off) saving(figsm2_11.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick)  legend(off) xtitle("") title("Avoid large-sized gatherings", size(vsmall))  

*Avoid crowded areas
twoway lpolyci behaviour15 age, level(84)  legend(off) saving(figsm2_12.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20 " " 30 " " 40 " " 50 " " 60 " " 70 " " 80 " " 90 " ", notick) legend(off) xtitle("") title("Avoid crowded areas", size(vsmall)) 

*Avoid going to shop
twoway lpolyci behaviour16 age, level(84)  legend(off) saving(figsm2_13.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20(10)90, labsize(tiny)) legend(off) xtitle("Age", size(vsmall)) title("Avoid going to shop", size(vsmall))  

*Eat separetely
twoway lpolyci behaviour18 age, level(84)  legend(off) saving(figsm2_14.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20(10)90, labsize(tiny)) legend(off) xtitle("Age", size(vsmall)) title("East separately", size(vsmall))  
		 	 
*Clean frequently touched surface inside the home
twoway lpolyci behaviour19 age, level(84)  legend(off) saving(figsm2_15.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20(10)90, labsize(tiny)) legend(off) xtitle("Age", size(vsmall)) title("Cleaned touched surface at home", size(vsmall)) 
		 
*Touching objects in public
twoway lpolyci behaviour20 age, level(84)  legend(off) saving(figsm2_16.gph, replace)  ///
		 ylabel(0(.2)1, labsize(vsmall))  xlabel(20(10)90, labsize(tiny)) legend(off) xtitle("Age", size(vsmall)) title("Avoided touching objects in public", size(vsmall))  
		 		 		 		 		 	 		 		 		 
graph combine figsm2_1.gph figsm2_2.gph figsm2_3.gph figsm2_4.gph figsm2_5.gph figsm2_6.gph figsm2_7.gph figsm2_8.gph figsm2_9.gph  ///
		figsm2_10.gph figsm2_11.gph figsm2_12.gph figsm2_13.gph figsm2_14.gph figsm2_15.gph figsm2_16.gph, ///
		xsize(15) ysize(20) col(4) scale(1.5)

*Figure SM.3 - All 20 items for compliance 
*Note: need to re-run the do-file and skip line 63
twoway lpolyci index age, level(84) legend(off)   ///
		 ylabel(6(2)20)  xlabel(20(5)90) legend(off) xtitle("Age") ytitle("Compliance with all 20 preventive measures")
	
*Figure SM.4 - With and without the 'not sure'
replace isolate_prospective=. if  i9_health=="Not sure"
replace isolation_willingness=. if i11_health=="Neither willing nor unwilling"

twoway lpolyci isolate_prospective age, level(84) legend(off)  ///
		 ylabel(.6(.1)1) title("panel a")   xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save sm4_1.gph, replace
			 

twoway lpolyci isolation_willingness age, level(84) legend(off)   ///
		 ylabel(.6(.1)1)  title("panel b")  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Willingness to isolate")  
graph save sm4_2.gph, replace
	
graph combine sm4_1.gph  sm4_2.gph , col(1) ysize(18) xsize(12)


*Figure SM5 - with country fixed-effects, covariates for time and also individual-level factors   
eststo m1: logit isolate_prospective ib50.age  i.country  ib1.time1_time2_time3  woman children alone  status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel a") level(84)  xlabel(20(10)90)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save sm5_1.gph, replace

eststo m2: reg isolation_willingness  ib50.age  i.country  ib1.time1_time2_time3  woman children  alone  status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel b") level(84)  xlabel(20(10)90)  legend(off) xtitle("Age") ytitle("Willingness isolation")  
graph save sm5_2.gph, replace
	
eststo m3: reg index  i.country ib50.age  i.country  ib1.time1_time2_time3  woman children  alone status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel c") level(84)  xlabel(20(10)90) ylabel(6(2)16)  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Compliance with preventive measures")  
graph save sm5_3.gph, replace

graph combine sm5_1.gph sm5_2.gph sm5_3.gph, col(1) xsize(10) ysize(15) 

*Figure SM6 - with country fixed-effects, region fixed effects, covariates for time and also individual-level factors   
eststo o1: logit isolate_prospective ib50.age  i.country i.region_fe ib1.time1_time2_time3  woman children alone  status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel a") level(84)  xlabel(20(10)89)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save sm6_1.gph, replace

eststo o2: reg isolation_willingness  ib50.age  i.country  i.region_fe ib1.time1_time2_time3  woman children  alone  status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel b") level(84)  xlabel(20(10)89)  legend(off) xtitle("Age") ytitle("Willingness isolation")  
graph save sm6_2.gph, replace
	
eststo o3: reg index  i.country ib50.age  i.country i.region_fe  ib1.time1_time2_time3  woman children  alone status2 status3 status4 status5 status6 status7
margins, at(age=(18(2)89))
marginsplot, ylabel(.4(.1)1) title("panel c") level(84)  xlabel(20(10)89) ylabel(6(2)16)  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Compliance with preventive measures")  
graph save sm6_3.gph, replace

graph combine sm6_1.gph sm6_2.gph sm6_3.gph, col(1) xsize(10) ysize(15) 

*To get the regression outputs:
esttab ///
      m1 m2 m3  ///
       using "TableSM5.rtf", ///
	   label mlabels(,titles) nogap compress b(2) se(2) nostar nonumbers interaction(" X ") drop(*country*)   replace
	
esttab ///
      o1 o2 o3  ///
       using "TableSM6.rtf", ///
	   label mlabels(,titles) nogap compress b(2) se(2) nostar nonumbers interaction(" X ") drop(*country*)  drop(*region_fe*)  replace
	
*Figure SM7. Local regressions with alternative bandwidth (0.7)
twoway lpolyci isolate_prospective age, level(84) legend(off) bwidth(0.7)  ///
		 ylabel(.6(.1)1) title("panel a")   xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save sm7_1.gph, replace
	
twoway lpolyci isolation_willingness age, level(84) legend(off) bwidth(0.7)  ///
		 ylabel(.6(.1)1)  title("panel b")  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Willingness to isolate")  
graph save sm7_2.gph, replace	
	
twoway lpolyci index age, level(84) legend(off) bwidth(0.7)  ///
		 ylabel(6(2)16)  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Compliance with preventive measures")  
graph save sm7_3.gph, replace
	
graph combine sm7_1.gph sm7_2.gph sm7_3.gph, col(1) xsize(10) ysize(15) 
	
*Figure SM8. Local regressions with alternative bandwidth (0.9)
	
twoway lpolyci isolate_prospective age, level(84) legend(off) bwidth(0.9)  ///
		 ylabel(.6(.1)1) title("panel a")   xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Prospective isolation")  
graph save sm8_1.gph, replace
	
twoway lpolyci isolation_willingness age, level(84) legend(off) bwidth(0.9)  ///
		 ylabel(.6(.1)1)  title("panel b")  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Willingness to isolate")  
graph save sm8_2.gph, replace	
	
twoway lpolyci index age, level(84) legend(off) bwidth(0.9)  ///
		 ylabel(6(2)16)  xlabel(20(5)90)  legend(off) xtitle("Age") ytitle("Compliance with preventive measures")  
graph save sm8_3.gph, replace
	
graph combine sm8_1.gph sm8_2.gph sm8_3.gph, col(1) xsize(10) ysize(15) 
